package main;

public class Class2 {
	
	
	
	
	
	
	
	/** 
	* searches for a value in sorted array 
	* 
	* @param array 
	* array to search in 
	* @param value 
	* searched value 
	* @param left 
	* index of left boundary 
	* @param right 
	* index of right boundary 
	* @return position of searched value, if it presents in the array or -1, if 
	* it is absent 
	*/ 
	int binarySearch(int[] array, int value, int left, int right) { 
	   if (left > right) 
	        return -1; 
	  int middle = (left + right) / 2; 
	  if (array[middle] == value) 
	       return middle; 
	 else if (array[middle] > value) 
	      return binarySearch(array, value, left, middle - 1); 
	  else 
	return binarySearch(array, value, middle + 1, right); 
	}

	
	public int sub(int a, int b){
		return a - b;
	}
	
	
	
	
	
	
	
	
	
	
	public static String Encode (String a) {
        char lastchar = (char)800;
        int f = 1;
        for (int i = 0; i < a.length(); i++){
            if (i < 2 || Character.isDigit(a.charAt(i - 1))){
                f = 1;
            } else {
            	f = 2;
            }
            if (a.charAt(i) == lastchar){
                if (Character.isDigit(a.charAt(i - f))){
                    a = a.substring(0, i - f) 
                    	+ (Integer.parseInt(Character.toString(a.charAt(i - f))) + 1) 
                    	+ a.substring(i);
                    i--;
                } else {
                    a = a.substring(0, i - 1) + 2 + a.substring(i);
                }
            } else {
                lastchar = a.charAt(i);
            }
        }
        return a;
    }

	
}
